home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / PRG / Mac_F2C_1.3.2.sit / Mac F2C 1.3.2 / Mac F2C Libraries / libF77 Sources / s_catow.c < prev    next >
Text File  |  1995-01-28  |  1KB  |  70 lines

  1. /* Variant of s_cat that allows the target of a concatenation to */
  2. /* appear on its right-hand side (contrary to the Fortran 77 Standard). */
  3.  
  4. #include "f2c.h"
  5. #undef abs
  6. #ifdef KR_headers
  7.  extern char *malloc();
  8.  extern void free();
  9. #else
  10. #include "stdlib.h"
  11. #endif
  12. #include "string.h"
  13.  
  14.  static VOID
  15. #ifdef KR_headers
  16. s_cat0(lp, rpp, rnp, n, ll) char *lp, *rpp[]; ftnlen rnp[], n, ll;
  17. #else
  18. s_cat0(char *lp, char *rpp[], ftnlen rnp[], ftnlen n, ftnlen ll)
  19. #endif
  20. {
  21.     ftnlen i, nc;
  22.     char *rp;
  23.  
  24.     for(i = 0 ; i < n ; ++i) {
  25.         nc = ll;
  26.         if(rnp[i] < nc)
  27.             nc = rnp[i];
  28.         ll -= nc;
  29.         rp = rpp[i];
  30.         while(--nc >= 0)
  31.             *lp++ = *rp++;
  32.         }
  33.     while(--ll >= 0)
  34.         *lp++ = ' ';
  35.     }
  36.  
  37.  VOID
  38. #ifdef KR_headers
  39. s_cat(lp, rpp, rnp, np, ll) char *lp, *rpp[]; ftnlen rnp[], *np, ll;
  40. #else
  41. s_cat(char *lp, char *rpp[], ftnlen rnp[], ftnlen *np, ftnlen ll)
  42. #endif
  43. {
  44.     ftnlen i, L, m, n;
  45.     char *lpe, *rp;
  46.  
  47.     n = *np;
  48.     lpe = lp;
  49.     L = ll;
  50.     i = 0;
  51.     while(i < n) {
  52.         rp = rpp[i];
  53.         m = rnp[i++];
  54.         if (rp >= lpe || rp + m <= lp) {
  55.             if ((L -= m) <= 0) {
  56.                 n = i;
  57.                 break;
  58.                 }
  59.             lpe += m;
  60.             continue;
  61.             }
  62.         lpe = malloc(ll);
  63.         s_cat0(lpe, rpp, rnp, n, ll);
  64.         memcpy(lp, lpe, ll);
  65.         free(lpe);
  66.         return;
  67.         }
  68.     s_cat0(lp, rpp, rnp, n, ll);
  69.     }
  70.